package cn.woblog.android.common.skin.demo;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import cn.woblog.android.common.skin.ThemeInfo;

public class ThemeListAdapter extends BaseAdapter {

	private Context context;
	private OnThemeChangedListener onThemeChangedListener;
	private List<ThemeInfo> datas;

	public ThemeListAdapter(Context context, List<ThemeInfo> datas, OnThemeChangedListener onThemeChangedListener) {
		super();
		this.context = context;
		this.datas = datas;
		this.onThemeChangedListener = onThemeChangedListener;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int position) {

		return null;
	}

	@Override
	public long getItemId(int position) {

		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.item, null);
		}
		ThemeInfo themeInfo = datas.get(position);
		TextView tv_title = (TextView) convertView.findViewById(R.id.tv_title);
		tv_title.setText(themeInfo.getTitle());
		Button bt_controll = (Button) convertView.findViewById(R.id.bt_controll);
		if (themeInfo.isDefualt()) {
			bt_controll.setText("正在使用");
		} else {
			bt_controll.setText("切换");
			bt_controll.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					onThemeChangedListener.onThemeChanged(datas.get(position));
				}
			});
		}
		return convertView;
	}

	public static interface OnThemeChangedListener {
		void onThemeChanged(ThemeInfo info);
	}
}
